﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Spring.Context;
using Spring.Context.Support;
using XTeam.Document.Factory.ServiceInterface;
using XTeam.Document.Entities.Words;

namespace XTeam.Document.Controllers.Words
{
    public class HomeController : BasicController
    {
        private IWordsService _wordsService;
        public HomeController()
        {
            IApplicationContext _context = ContextRegistry.GetContext();
            _wordsService = (IWordsService)_context.GetObject("WordsService");
        }
        public ActionResult Main()
        {
            return View();
        }

        public ActionResult Card(string word = "")
        {
            var entry = _wordsService.FindWord(word);
            return View(entry);
        }

        public ActionResult List(int p = 0)
        {
            int totalRows = 0;
            int pageSize = 15;
            IList<WordsEntity> resultTable = _wordsService.Search(null, p, pageSize, out totalRows);
            string hrefFormat = Url.Action(string.Format("{0}", RouteData.Values["Action"]), new { p = "{0}" });
            ViewBag.Pager = this.CreatePager(Url.Action("List", new { p = "{0}" }), p, pageSize, totalRows);
            return View(resultTable);
        }


    }
}
